package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CallableTest {
	public static void main(String[] args) {
		ExecutorService pool = Executors.newFixedThreadPool(2);
		Future<Object> f1 = pool.submit(new MyCallable("A"));
		Future<Object> f2 = pool.submit(new MyCallable("B"));
		try {
			System.out.println(">>>"+f1.get().toString());
			System.out.println(">>>"+f2.get().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			pool.shutdown();
		}
	}
}

class MyCallable implements Callable<Object>{
	private String oid;
	MyCallable(String oid) {
		this.oid = oid;
	}
	@Override
	public Object call() throws Exception {
		return oid+"任务返回的内容";
	}
}
